home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 008 / mapovlay.arc / MAPDOS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1985-05-11  |  4.4 KB  |  115 lines

  1. { Configuration routine for MAP.PAS for the PC/MS-DOS family of Turbo Pascal compilers }
  2.  
  3. const MachineType = 'DOS';
  4.       QuantizationSize = 256;
  5.       PaddingByte = $00;
  6.  
  7. var Buffer: array[1..QuantizationSize] of byte;
  8.  
  9. function EndOfOverlay(var Fyle: BinaryFile;
  10.                       var Index,AmbiguousCount: integer;
  11.                       RetryCount: integer): boolean;
  12.   { Return true if last sector of an overlay is in the buffer }
  13.  
  14.   function EndCheck(StartingPoint: integer): boolean;
  15.     { Check for a valid end sequence at the indicated address }
  16.     const SimpleReturnString = #139#229#93#195;  { Look for BP, SP and RET instructions }
  17.           ComplexReturnString1 = #139#229#93#194; { Look for BP, SP and RET nn instructions }
  18.           ComplexReturnString2 = #139#229#93#233; { Look for BP, SP and JMP xxxx instructions (functions returning strings) }
  19.     type ChrStr = string[4];
  20.  
  21.     function TestEndingPrefix(Index: integer;Ending: ChrStr): boolean;
  22.       { Test for the ending prefix ending at the given index into Buffer (may be negative) }
  23.       var TempBuffer: array[1..384] of char;
  24.  
  25.       function CompareString(var BufferAddr;TestString: ChrStr): boolean;
  26.         { Test the string against the buffer }
  27.         var Buffer: array[1..255] of char absolute BufferAddr;
  28.         begin
  29.         CompareString := copy(Buffer,1,length(TestString)) = TestString
  30.         end;
  31.  
  32.       begin
  33.       if Index < length(Ending)
  34.        then
  35.         if filepos(Fyle)<3
  36.          then
  37.           TestEndingPrefix := false              { Nothing previous to look for, must return false }
  38.          else
  39.           begin
  40.           seek(Fyle,filepos(Fyle)-3);            { Look back at the data previous to this buffer-full }
  41.           blockread(Fyle,TempBuffer,3);          { Get data and restore file pointer }
  42.           TestEndingPrefix := CompareString(TempBuffer[129+Index-length(Ending)],Ending)
  43.           end
  44.        else
  45.         TestEndingPrefix := CompareString(Buffer[Index-length(Ending)+1],Ending)
  46.       end;
  47.  
  48.     begin
  49.     if TestEndingPrefix(StartingPoint,SimpleReturnString) { Look for a simple RET }
  50.      then
  51.       EndCheck := true
  52.      else
  53.       if TestEndingPrefix(StartingPoint-2,ComplexReturnString1) { Look for a RET nn }
  54.        then
  55.         EndCheck := true
  56.        else                                      { Handle the case of a function returning a string }
  57.         EndCheck := TestEndingPrefix(StartingPoint-2,ComplexReturnString2) { Look for a JMP xxxx }
  58.     end;
  59.  
  60.   begin
  61.   Index := QuantizationSize;
  62.   if EndCheck(QuantizationSize)
  63.    then
  64.     begin                                        { If last byte in record is a return instruction, }
  65.     EndOfOverlay := not odd(RetryCount shr AmbiguousCount); { Check how to handle the ambiguity this time }
  66.     AmbiguousCount := succ(AmbiguousCount)
  67.     end
  68.    else
  69.     begin                                        { Look for a return instruction padded out with 00's }
  70.     while (Index>=1) and (Buffer[Index]=PaddingByte) do
  71.       Index := pred(Index);
  72.     if Index=QuantizationSize
  73.      then
  74.       EndOfOverlay := false                      { We've already eliminated the last byte as an end point }
  75.      else
  76.       if EndCheck(Index+1)
  77.        then
  78.         begin
  79.         EndOfOverlay := true;                    { In this case the last byte of the RET nn instruction was a 0 }
  80.         Index := succ(Index)
  81.         end
  82.        else
  83.         if Index=0
  84.          then
  85.           EndOfOverlay := false                  { This assumes that there is no such thing as a RET 0 }
  86.          else
  87.           EndOfOverlay := EndCheck(Index)
  88.     end
  89.   end;
  90.  
  91. procedure CheckVersion;
  92.   { This routine is not executed, it only serves to check that the correct
  93.     configuration module is being used. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99. (******************************************************************************
  100.            You are attempting to compile this program with the wrong
  101.            configuration file.  You need to change the include file
  102.            directive located about 20 lines from the beginning of
  103.            MAP.PAS to:
  104.                             {$I MAPCPM.PAS}
  105. ******************************************************************************)
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.   var Address: byte absolute $0000:$0000;
  113.   begin
  114.   end;
  115.